//
//  ContactsViewController.m
//  HikingManagerRemake
//
//  Created by FENGYL on 2016/12/24.
//  Copyright © 2016年 FENGYL. All rights reserved.
//

#import "ContactsViewController.h"
#import "AccountSettingViewController.h"

static NSString * cellIdentifier = @"";

@interface ContactsViewController ()<UITableViewDelegate,UITableViewDataSource,UISearchControllerDelegate>

@property (weak, nonatomic) IBOutlet UISearchBar *searchBar;
@property (weak, nonatomic) IBOutlet UITableView *friendsListTableView;

@property (strong , nonatomic) UISearchController * searchController;

@end

@implementation ContactsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.friendsListTableView.tableFooterView = [[UIView alloc]init];
    self.friendsListTableView.delegate = self;
    self.friendsListTableView.dataSource = self;
    
    self.searchBar.barTintColor = [UIColor whiteColor];
    self.searchBar.showsScopeBar=YES;
    self.searchBar.scopeButtonTitles = @[@"Friends",@"Groups"];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 1;
    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    
    if (!cell) {
        
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
        
    }
    
    [cell.textLabel setText:@"ll"];
    
    return cell;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    
    //编辑好友
    UIAlertAction * editContactAction = [UIAlertAction actionWithTitle:@"EditContact" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    //传送消息
    UIAlertAction * sendMessageAction = [UIAlertAction actionWithTitle:@"SendMessage" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    //删除好友
    UIAlertAction * deleteContactAction = [UIAlertAction actionWithTitle:@"DeleteContact" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        
        UIAlertController * deleteAlertController = [UIAlertController alertControllerWithTitle:@"Delete Contact" message:@"Delete the contact?" preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction * deleteAction = [UIAlertAction actionWithTitle:@"Delete" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        
        UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
        
        [deleteAlertController addAction:deleteAction];
        [deleteAlertController addAction:cancelAction];
        
        [self presentViewController:deleteAlertController animated:YES completion:nil];
        
    }];
    
    //Cancel
    UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    [alertController addAction:editContactAction];
    [alertController addAction:sendMessageAction];
    [alertController addAction:deleteContactAction];
    [alertController addAction:cancelAction];
    
    [self presentViewController:alertController animated:YES completion:nil];
}

- (IBAction)addContact:(id)sender {
    
    UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"Welcome" bundle:[NSBundle mainBundle]];
    
    AccountSettingViewController * accountSettingViewController = [storyboard instantiateViewControllerWithIdentifier:@"AccountSettingViewController"];
    
    [accountSettingViewController.navigationItem setTitle:@"Add Contact"];
    
    [self.navigationController showViewController:accountSettingViewController sender:nil];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
